package com.xbongbong.pro.enums;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author 李翔
 * @date 2023/3/3
 * @description 共享权限支持额的表单枚举
 */
@Getter
public enum ShareSupportFormEnum {

    /**
     * 市场管理：市场活动、销售线索
     */
//    MARKET_MANAGEMENT(XbbRefTypeEnum.MARKET_MANAGEMENT.getAlias(), Arrays.asList(XbbRefTypeEnum.MARKET_ACTIVITY.getCode(),
//            XbbRefTypeEnum.CLUE.getCode())),
    /**
     * CRM：客户管理、联系人、跟进记录、工作报告、销售机会、报价单、退货退款、合同订单
     */
//    CRM(XbbRefTypeEnum.CRM.getAlias(), Arrays.asList(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(),
//            XbbRefTypeEnum.CONTACT.getCode(), XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), XbbRefTypeEnum.WORK_REPORT.getCode(),
//            XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), XbbRefTypeEnum.QUOTATION.getCode(), XbbRefTypeEnum.REFUND.getCode(),
//            XbbRefTypeEnum.CONTRACT.getCode())),
    /**
     * 进销存：
     */
//    JXC(XbbRefTypeEnum.JXC.getAlias(), Arrays.asList(XbbRefTypeEnum.PURCHASE_MANAGEMENT.getCode(),
//            XbbRefTypeEnum.PRODUCTION_MANAGEMENT.getCode(), XbbRefTypeEnum.INVENTORY_MANAGEMENT.getCode(), XbbRefTypeEnum.INSTOCK.getCode(),
//            XbbRefTypeEnum.OUTSTOCK.getCode(), XbbRefTypeEnum.WAREHOUSE.getCode())),
    /**
     * 资金：销项发票、资金调拨单、应收款、回款单、其他收入单、其他支出单、进项发票、付款计划、付款单
     */
//    FUND_MANAGEMENT(XbbRefTypeEnum.FUND_MANAGEMENT.getAlias(), Arrays.asList(XbbRefTypeEnum.INVOICE.getCode(),
//            XbbRefTypeEnum.FUND_TRANSFER.getCode(), XbbRefTypeEnum.PAYMENT.getCode(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(),
//            XbbRefTypeEnum.OTHER_INCOME.getCode(), XbbRefTypeEnum.OTHER_EXPENSE.getCode(), XbbRefTypeEnum.PURCHASE_INVOICE.getCode(),
//            XbbRefTypeEnum.PAY_PLAN.getCode(), XbbRefTypeEnum.PAY_SHEET.getCode())),
    /**
     * 工单2.0：默认工单
     */
//    WORK_ORDER_V2_CENTER(XbbRefTypeEnum.WORK_ORDER_V2_CENTER.getAlias(), Arrays.asList(XbbRefTypeEnum.WORK_ORDER_V2.getCode(),
//            XbbRefTypeEnum.RECEIPT_ORDER.getCode(), XbbRefTypeEnum.SERVICE_PROJECT.getCode(), XbbRefTypeEnum.SLA_LOG.getCode())),

    /**
     * 1+旗
     */
    CRM(XbbRefTypeEnum.CRM.getAlias(), Arrays.asList(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(),
            XbbRefTypeEnum.CONTACT.getCode(), XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(),
            XbbRefTypeEnum.CONTRACT.getCode())),
    ;
    private final String appAlias;
    private final List<Integer> businessTypeList;
    ShareSupportFormEnum(String appAlias,List<Integer> businessTypeList) {
        this.appAlias = appAlias;
        this.businessTypeList = businessTypeList;
    }

    /**
     * @return 支持的app列标
     */
    public static List<String> getSupportAppList() {
        List<String> res = new ArrayList<>(values().length);
        for (ShareSupportFormEnum shareSupportFormEnum : values()) {
            res.add(shareSupportFormEnum.appAlias);
        }
        return res;
    }

    /**
     *
     * @param appAlias
     * @return 支持的表单业务code
     */
    public static List<Integer> getSupportListByAppAlias(String appAlias) {
        for (ShareSupportFormEnum shareSupportFormEnum : values()) {
            if (Objects.equals(shareSupportFormEnum.getAppAlias(), appAlias)) {
                return shareSupportFormEnum.businessTypeList;
            }
        }
        return new ArrayList<>();
    }

    /**
     *
     * @return 不支持的业务code
     */
    public static List<Integer> getNonsupportList() {
        //    以下应用不支持共享权限设置：经销商应用、营销管理（经销商）应用、客户运营（企微）、引流获客（企微）、会话存档（企微）、企微群（企微）、审批
        //todo-leex 多平台那边处理
        return Arrays.asList(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(),XbbRefTypeEnum.MARKETING_MANAGEMENT.getCode(),XbbRefTypeEnum.APPROVAL.getCode());
    }

}
